package cn.tedu.egmvc1.controller;

import ch.qos.logback.core.joran.util.beans.BeanUtil;
import cn.tedu.egmvc1.mapper.EmpMapper;
import cn.tedu.egmvc1.pojo.DTO.EmpDTO;
import cn.tedu.egmvc1.pojo.entity.Emp;
import cn.tedu.egmvc1.pojo.vo.EmpVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class EmpController {
    @Autowired
    private EmpMapper empMapper;
    @RequestMapping("/emp/insert")
    @ResponseBody
    public String insert(EmpDTO empDTO){
        Emp emp = new Emp();
        BeanUtils.copyProperties(empDTO,emp);
        empMapper.insertEmp(emp);
        return "添加成功";
    }

    @RequestMapping("/emp/select")
    @ResponseBody
    public List<EmpVO> select(){
        return empMapper.selectEmp();
    }

    @RequestMapping("/emp/update")
    @ResponseBody
    public String update(Emp emp){
        empMapper.updateEmp(emp);
        return "修改成功";
    }
    @RequestMapping("/emp/delete")
    @ResponseBody
    public String delete(Long id){

        empMapper.deleteEmp(id);
        return "删除成功";
    };
}
